package com.ayf.payment.game.api.controller.platform;

import com.ayf.payment.game.api.dto.platform.NetConfigDTO;
import com.ayf.payment.game.api.dto.platform.SettleConfigDTO;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.service.platform.NetConfigService;
import com.ayf.payment.game.api.service.platform.SettleConfigService;
import com.ayf.payment.game.api.type.CommonConstants;
import com.ayf.payment.game.api.utils.CommonResult;
import com.ayf.payment.game.api.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统设置
 *
 * @author wwl
 * @date 2020/3/6 21:01
 */
@RequestMapping("/t/sys")
@RestController
public class NetConfigController {

    @Autowired
    private NetConfigService netConfigService;

    @Autowired
    private SettleConfigService settleConfigService;

    /**
     * 获取网站设置
     * @return
     */
    @PostMapping("/netConfig")
    public CommonResult<NetConfigDTO> netConfig() {
        NetConfigDTO netConfigDTO=netConfigService.getNetConfig();
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "成功", netConfigDTO);
    }

    /**
     * 更新网站设置
     * @return
     */
    @PostMapping("/updateNetConfig")
    public CommonResult updateNetConfig(@RequestBody NetConfigDTO netConfigDTO) {
        if(netConfigDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(netConfigDTO.getId()==null){
            throw new ParameterException("id不能为空");
        }
        if(netConfigDTO.getNetName()==null){
            throw new ParameterException("网站名称不能为空");
        }
        if(netConfigDTO.getDomainName()==null){
            throw new ParameterException("主站域名不能为空");
        }
        if(netConfigDTO.getSettleBank()==null){
            throw new ParameterException("结算银行不能为空");
        }

        if(netConfigDTO.getCopyright()==null){
            throw new ParameterException("网站版权信息不能为空");
        }
        netConfigDTO.setLastUpdateTime(DateUtils.getNowDate());
        netConfigService.update(netConfigDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "成功", "");
    }

    /**
     * 获取网站结算设置
     * @return
     */
    @PostMapping("/getSettleConfig")
    public CommonResult<SettleConfigDTO> getSettleConfig() {
        SettleConfigDTO settleConfigDTO=settleConfigService.getSettleConfig();
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "成功", settleConfigDTO);
    }

    /**
     * 更新充值设置 提现设置
     * @return
     */
    @PostMapping("/updateSettleConfig")
    public CommonResult updateSettleConfig(@RequestBody SettleConfigDTO settleConfigDTO) {
        if(settleConfigDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(settleConfigDTO.getSettleCycle()==null){
            throw new ParameterException("结算周期不能为空");
        }
        if(settleConfigDTO.getMinWithdrawalAmount()==null){
            throw new ParameterException("最小提现金额不能为空");
        }
        if(settleConfigDTO.getFeeCustom()==null){
            throw new ParameterException("手续费自定义不能为空");
        }

        if(settleConfigDTO.getMaxRechargeAmount()==null){
            throw new ParameterException("最大充值金额不能为空");
        }
        if(settleConfigDTO.getMinRechargeAmount()==null){
            throw new ParameterException("最小充值金额不能为空");
        }
        settleConfigDTO.setLastUpdateTime(DateUtils.getNowDate());
        settleConfigService.updateSettleConfig(settleConfigDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "成功", "");
    }

}
